package com.qiangang.yan.tools.util;


import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: qiangang.yan
 * @CreateDate: 2019/8/3 9:17
 **/
public class LambdaUtil {

    public static <T, K, V> Map<K, V> tomap(List<T> list, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valMapper, BinaryOperator<V> mergeFunction) {
        Map<K, V> map = list.stream().collect(Collectors.toMap(keyMapper, valMapper, mergeFunction));
        return map;
    }

    public static <T, K, V> Map<K, V> tomap2(Collection<T> c, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valMapper) {
        Map<K, V> map = c.stream().collect(Collectors.toMap(keyMapper, valMapper, (k1, k2) -> k2));
        return map;
    }


}
